package com.pl.action;  

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pl.bean.OauthClientDetailsBean;
import com.pl.bean.ResultData;
import com.pl.common.Constant.sessionKey;
import com.pl.service.ManagePageService;
import com.pl.service.ManageUserService;
import com.pl.service.OauthClientDetailsService;
import com.pl.util.ResultDataUtil;

/**
 * 首页
 */
@Controller
@RequestMapping(value="index")
public class IndexAction {

	private static Logger log = LogManager.getLogger();
	
	@Resource(name="manageUserService")
	private ManageUserService manageUserService;
	
	@Resource(name="managePageService")
	private ManagePageService managePageService;
	
	@Autowired
	private OauthClientDetailsService oauthClientDetailsService;
	
	//上传地址的物理路径
	@Value("${UPLOAD_PATH}")
    private String realPathPrev;
	
	//上传地址的虚拟路径
    @Value("${UPLOAD_VIRTUAL_PATH}")
    private String virtualPath;
	
	/**
	 * 首页
	 */
	@RequestMapping(value="index")
	public String index(HttpServletRequest request){
		
		return "index/index";
	}
	
	/**
	 * 首页
	 */
	@RequestMapping(value="clientList")
	public String clientList(HttpServletRequest request){
		
		return "index/client";
	}
	
	/**
	 *  我能访问的客户端
	 */
	@RequestMapping(value="myClient")
	@ResponseBody
	public ResultData<List<OauthClientDetailsBean>> myClient(HttpServletRequest request){
		
		long userId = (Long)request.getSession().getAttribute(sessionKey.USER_ID.getValue());
		OauthClientDetailsBean param = new OauthClientDetailsBean();
		param.setParamUserId(userId);
		
		List<OauthClientDetailsBean> list = oauthClientDetailsService.getOauthClientDetails(param);
		
		return ResultDataUtil.ok(list);
	}
	

}
